<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增健康日报详情')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-healthdailyInfo-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">用户手机号：</label>
                <div class="col-sm-8">
                    <input id="userMobile" name="userMobile" class="form-control" type="text" onblur="selectMobile()" maxlength="32" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">用户名：</label>
                <div class="col-sm-8">
                    <input name="userName" id="userName" class="form-control" type="text" maxlength="100"  required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">归属公司：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                    	<input name="companyName" onclick="selectCompanyName()" id="companyName" type="text"  maxlength="100" placeholder="请选择归属公司" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">归属部门：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                    	<input name="departName" onclick="selectDepartName()" id="departName" type="text"  maxlength="100" placeholder="请选择归属部门" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">归属班组：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                    	<input name="teamName" onclick="selectTeamName()" id="teamName" type="text"  maxlength="100" placeholder="请选择归属班组" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否离开公司驻地：</label>
                <div class="col-sm-8">
                    <input name="comResidentFlag" class="form-control"  maxlength="1" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">目的地：</label>
                <div class="col-sm-8">
                    <input name="destination" class="form-control" maxlength="256" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">离开驻地时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="departureTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">离开驻地方式：</label>
                <div class="col-sm-8">
                    <input name="departureMode" class="form-control" maxlength="32" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">离开驻地车次航班：</label>
                <div class="col-sm-8">
                    <input name="departureInfo" class="form-control" maxlength="64" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">返回时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="returnTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">返回方式：</label>
                <div class="col-sm-8">
                    <input name="returnMode" class="form-control" maxlength="32" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">返回驻地车次航班：</label>
                <div class="col-sm-8">
                    <input name="returnInfo" class="form-control" maxlength="64" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">是否在疫区停留：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" name="epidemicAreaFlag" value = "0" required>
                        <label th:for="epidemicAreaFlag" th:text="是"></label>
                    </div>
                     <div class="radio-box">
                        <input type="radio" name="epidemicAreaFlag" value="1" required>
                        <label th:for="epidemicAreaFlag" th:text="否"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">是否疑患同乘：</label>
                <div class="col-sm-8">
                     <div class="radio-box">
                        <input type="radio" name="epidemicPersonFlag" value = "0" required>
                        <label th:for="epidemicPersonFlag" th:text="是"></label>
                    </div>
                     <div class="radio-box">
                        <input type="radio" name="epidemicPersonFlag" value="1"  required>
                        <label th:for="epidemicPersonFlag" th:text="否"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">目前地址：</label>
                <div class="col-sm-8">
                    <textarea id ="currentLocation"  name="currentLocation" maxlength="512" class="form-control" required></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">目前健康状态：</label>
                <div class="col-sm-8">
                   <div class="radio-box">
                        <input type="radio" id="healthStatus1" name="healthStatus" value = "0" required>
                        <label th:for="healthStatus" th:text="健康"></label>
                    </div>
                     <div class="radio-box">
                        <input type="radio" name="healthStatus" value="1" required>
                        <label th:for="healthStatus" th:text="异常"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否到岗办公：</label>
                <div class="col-sm-8">
                   <div class="radio-box">
                        <input type="radio" id="workStatus1" name="workStatus" value = "0" required>
                        <label th:for="workStatus" th:text="是"></label>
                    </div>
                     <div class="radio-box">
                        <input type="radio" id="workStatus2" name="workStatus" value="1"  required>
                        <label th:for="workStatus" th:text="否"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">到岗方式：</label>
                <div class="col-sm-8">
                    <input name="workMode" class="form-control" maxlength="32" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">上午体温：</label>
                <div class="col-sm-8">
                    <input name="amTemperature" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">下午体温：</label>
                <div class="col-sm-8">
                    <input name="pmTemperature" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">组织编码：</label>
                <div class="col-sm-8">
                    <input name="deptCode" class="form-control" type="text" maxlength="100" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">组织名称：</label>
                <div class="col-sm-8">
                    <input name="deptName" class="form-control" type="text" maxlength="100" required>
                </div>
            </div>
             <div class="form-group" style="display:none">    
                <label class="col-sm-3 control-label is-required">id：</label>
                <div class="col-sm-8">
                    <input name="id" class="form-control" type="text" maxlength="100" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "healthinfo/healthdailyInfo";
        var isFirst="";
   	 /* 	$("#form-healthdailyInfo-add").validate({
            focusCleanup: true
        });  */

      function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-healthdailyInfo-add').serialize());
                //如果该手机号未存在user表中
                if(isFirst=="1"){
                	 $.operate.save(ctx + "healthinfo/healthuserinfo/add", $('#form-healthdailyInfo-add').serialize());
                }else{
                	 $.operate.save(ctx + "healthinfo/editByMobile", $('#form-healthdailyInfo-add').serialize()); 
                }
            }
        } 

        $("input[name='departureTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='returnTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='reportingDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='reportingTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
      
        function selectMobile(){
        	var userMobile=$("#userMobile").val();
        	var myDate = new Date();             
        	var year=myDate.getFullYear();        //获取当前年
        	var month=myDate.getMonth()+1;   //获取当前月
        	var date=myDate.getDate();            //获取当前日
        	var today = year+"-"+month+"-"+date;
        	if(userMobile!=""){
        		queryDaily(userMobile,today);
        	}
        	
        }
        
		function queryDaily(userMobile,today) {
			url=ctx + "healthinfo/queryByMobile";
			$.ajax({
				cache : true,
				type : "POST",
				url :url,
				data : {
					"userMobile": userMobile,
					"today": today,
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					if(data!=""){
						layer.alert('今日健康日报已提交,请勿重复提交', {icon: 6})
					}else{
						console.log("未提交")
						queryUserByMobile(userMobile);
					}
					
				}
			});
		}
		
		
		function queryUserByMobile(userMobile) {
			url=ctx + "healthinfo/queryUserByMobile";
			$.ajax({
				cache : true,
				type : "POST",
				url :url,
				data : {
					"userMobile": userMobile,
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					if(data==""){
						isFirst = "1";
					}else{
						isFirst = "0";	
						
						$("input[name='userName']").val(data.userName);
						$("input[name='companyName']").val(data.companyName);
						
						
						//公司部门班组不可点击
						$("#companyName").attr("onfocus", "this.blur()");
						$("#departName").attr("onfocus", "this.blur()");
						$("#teamName").attr("onfocus", "this.blur()");
						
						$("input[name='departName']").val(data.departName);
						$("input[name='teamName']").val(data.teamName);
						$("input[name='comResidentFlag']").val(data.comResidentFlag);
						$("input[name='destination']").val(data.destination);
						$("input[name='departureTime']").val(data.departureTime);
						$("input[name='departureMode']").val(data.departureMode);
						$("input[name='departureInfo']").val(data.departureInfo);
						$("input[name='returnTime']").val(data.returnTime);
						$("input[name='returnMode']").val(data.returnMode);
						$("input[name='returnInfo']").val(data.returnInfo);
						
						//单选框回显
						$(":radio[name='epidemicAreaFlag'][value='"+data.epidemicAreaFlag+"']").prop("checked", true);
            			$(":radio[name='epidemicAreaFlag'][value='"+data.epidemicAreaFlag+"']").parent("div").attr("class","iradio-blue hover checked");
						
						
						$(":radio[name='epidemicPersonFlag'][value='"+data.epidemicPersonFlag+"']").prop("checked", true);
            			$(":radio[name='epidemicPersonFlag'][value='"+data.epidemicPersonFlag+"']").parent("div").attr("class","iradio-blue hover checked");
						
						
						$("#currentLocation").val(data.currentLocation);
						
						
						$(":radio[name='healthStatus'][value='"+data.healthStatus+"']").prop("checked", true);
            			$(":radio[name='healthStatus'][value='"+data.healthStatus+"']").parent("div").attr("class","iradio-blue hover checked");
						
						
						$(":radio[name='workStatus'][value='"+data.workStatus+"']").prop("checked", true);
            			$(":radio[name='workStatus'][value='"+data.workStatus+"']").parent("div").attr("class","iradio-blue hover checked");
						
						
						$("input[name='workMode']").val(data.workMode);
						$("input[name='reportingDate']").val(data.reportingDate);
						$("input[name='reportingTime']").val(data.reportingTime);
						
						$("input[name='amTemperature']").val(data.amTemperature);
						$("input[name='pmTemperature']").val(data.pmTemperature);
						$("input[name='deptCode']").val(data.deptCode);
						$("input[name='deptName']").val(data.deptName);
						$("input[name='id']").val(data.id);
						
					}
					
				}
			});
		}
		
		 /*用户管理-新增-选择部门树*/
        function selectcompanyName() {
        	/* var url = ctx + "system/dept/simpplelist";
			$.modal.open('选择部门',"auto","auto",url,doSubmit); */
		}
		 
        function doSubmit(index, layero){
			alert(1)
		}
        
        
        $().ready(function() {
        	 $("#form-healthdailyInfo-add").validate({
        		 rules: {
        	   userMobile:{
   				required:true,
   				isPhone:true
   			}
        	  },
        	        messages: {
        	   userMobile:{
   				required:"请输入手机号",
   				isPhone:"请填写正确的11位手机号"
   			}
        	  }
        	    });
        	});
    </script>
</body>
</html>